fix: security hardening — path traversal, trust proxy, image allowlist#394
Merged
fix: security hardening — path traversal, trust proxy, image allowlist#394
Conversation
1. /api/opencode/models: validate workingDir with realpath + allowed-roots
check, matching the existing guard in /api/sessions/create.
2. Express trust proxy: set app.set('trust proxy', true) when TRUST_PROXY
is enabled so req.ip returns the real client IP for all rate limiters.
3. Markdown img renderer: restrict src to https: and data:image/ protocols
to prevent tracking beacons and arbitrary protocol access from model output.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c28cf6d to
938d369
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/api/opencode/models: AddedrealpathSync+ allowed-roots validation toworkingDir, matching the existing guard in/api/sessions/create. Prevents reading arbitrary filesystem paths via the models endpoint.app.set('trust proxy', true)early in Express setup (gated onTRUST_PROXYconfig). This ensuresreq.ipreturns the real client IP behind nginx, so all rate limiters (API global, auth endpoint) work correctly.imgrenderer inChatViewnow only allowshttps:anddata:image/URIs. Other protocols (http, ftp, etc.) are blocked with a placeholder, preventing tracking beacons or protocol abuse from model-generated markdown.Test plan
npm run lint— 0 errorsnpm test— 1600/1600 tests pass/api/opencode/models?workingDir=/etcreturns 403TRUST_PROXY=truebehind nginxhttps://src render normallyhttp://src show blocked placeholder🤖 Generated with Claude Code